Skip to content

Support quoted image paths and preserve prompt in CLI image command - #1206

Open
nordicnode wants to merge 1 commit into
CodebuffAI:mainfrom
nordicnode:fix-cli-image-command-args
Open

Support quoted image paths and preserve prompt in CLI image command#1206
nordicnode wants to merge 1 commit into
CodebuffAI:mainfrom
nordicnode:fix-cli-image-command-args

Conversation

@nordicnode

Copy link
Copy Markdown

Support quoted image paths and preserve prompt in CLI image command

Summary

• Fixes /image <path> [message] command parsing in the CLI to properly handle quoted paths ("..." and '...') and backslash-escaped spaces (\ ).
• Previously, args.trim().split(/\s+/) broke paths with spaces (common for screenshots on macOS/Windows) into separate tokens, corrupting the image filename (e.g. "/path/to/my causing a file-not-found error) and leaking the remainder into the message.
• Extracts parseImageCommandArgs into a standalone, pure utility (cli/src/commands/parse-image-args.ts) that correctly isolates the image path from the accompanying message.
• In cli/src/commands/command-registry.ts, preserves any returned prompt message in params.setInputValue so the user's instructions are retained in the input field alongside the attached image rather than being wiped by clearInput(params).
• Replaces the duplicated test parser in cli/src/commands/__tests__/image.test.ts with the real utility and adds unit test cases for quoted paths with spaces, escaped spaces, and quote edge cases.

Test plan

[✓] bun test --config=/dev/null src/commands/__tests__/image.test.ts — 16 pass, 0 fail (added tests for double/single quoted paths with spaces, escaped spaces, and prompt retention)
[✓] bun run --cwd cli typecheck — 0 errors
[✓] PR hygiene checks pass cleanly

@codebuff-team

Copy link
Copy Markdown
Contributor

Good find and a clean fix. The old args.trim().split(/\s+/) in image.ts genuinely broke on macOS/Windows screenshot filenames containing spaces (e.g. Screenshot 2026-09-02 at 10.00.00.png), and the remaining message returned from handleImageCommand was previously discarded in command-registry.ts via clearInput(params) regardless of content — so this is a real bug fix, not just refactoring.

The extraction into parse-image-args.ts is sensible, and the tests in image.test.ts cover the interesting cases: double/single quotes, escaped spaces, empty quotes, quoted-path-only. Nice touch testing "" please analyze this returning null.

A few things worth double-checking before this lands:

  • Unclosed quotes ("path with no closing quote) fall through silently to the escaped-space branch and treat the leading " as a literal path character — probably fine, but worth a test case documenting the intended behavior.
  • Quote handling doesn't verify anything follows the closing quote besides whitespace, so "path"extra would produce message = 'extra' glued oddly, but this is a minor edge case.
  • No unescaping for backslash-escaped quote characters inside a quoted path, but that's an acceptable scope limit for a first pass.

Small, in-scope, correctly tested — this looks portable as-is.

@codebuff-team codebuff-team added bot:triaged Classified by the community triage bot pr:port-candidate Worth porting into the private source tree labels Sep 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:triaged Classified by the community triage bot pr:port-candidate Worth porting into the private source tree

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants